package ldh.im.fxbase.data.pojo.status;

import ldh.rpc.dto.ValueEnum;
import ldh.im.dto.enums.MessageActionStatus;

public enum ImMessageActionStatus implements ValueEnum<Byte> {
    // 发送端和接受端
    none(0, "空"),                  // 未知
    // 发送端
    withdraw(6, "撤回"),            // 撤回
    withdrawed(7, "已撤回"),        // 撤回并同步到服务器

    delete(9, "用户删除"),              // 用户删除
    deleted(10, "已删除"),            // 用户删除并同步到服务器

    // 接收端
    read(1, "读"),                  // 已阅读，需要同步到服务器端
    readed(2, "已读"),               // 已读并同步到服务器
    ;

    private Byte value;
    private String desc;

    private ImMessageActionStatus(Integer value, String desc){
        this.value = value.byteValue();
        this.desc = desc;
    }

    @Override
    public Byte getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static ImMessageActionStatus wrap(MessageActionStatus messageActionStatus, boolean isSender) {
        if (messageActionStatus == null) {
            return ImMessageActionStatus.none;
        } else if (messageActionStatus == MessageActionStatus.none) {
            return ImMessageActionStatus.none;
        } else if (messageActionStatus == MessageActionStatus.readed) {
            return ImMessageActionStatus.readed;
        } else if (messageActionStatus == MessageActionStatus.withdrawed) {
            return ImMessageActionStatus.withdrawed;
        } else if (messageActionStatus == MessageActionStatus.userDelete) {
            return ImMessageActionStatus.deleted;
        }
        throw new RuntimeException("不支持这种类型:" + messageActionStatus.name());
    }

    public static ImMessageActionStatus getByValue(Integer value) {
        if (value == null) return null;
        for (ImMessageActionStatus messageStatus : ImMessageActionStatus.values()) {
            if (messageStatus.getValue() == value.byteValue()) {
                return messageStatus;
            }
        }

        throw new RuntimeException("ImMessageActionStatus不支持这个值：" + value);
    }


    // 是否撤回动作
    public boolean isWithdraw() {
        return this == withdraw || this == withdrawed;
    }

    // 是否读动作
    public boolean isRead() {
        return this == read || this == readed;
    }

}
